package com.example.controller;

import com.example.Utility.objIsNull;
import com.example.instrument.getOpenIdutil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Slf4j
@RestController
@RequestMapping("/api")
public class getWxOpenId {
    /**
     * appid
     */
    @Value("${WeChat.appid}")
    private String appid;
    /**
     * secret
     */
    @Value("${WeChat.secret}")
    private String secret;

    @RequestMapping("/getOpenid")
    public String getUserOpenid(String code) {
        if (objIsNull.isNull(code)) {
            log.error("code is null");
        }
        // 获取微信小程序的openid
        getOpenIdutil getOpenid = new getOpenIdutil();
        return getOpenid.getOpenid(appid, code, secret);
    }
}
